home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLSRC.PAK / CONTROL.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  6.5 KB  |  287 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1991, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.7  $
  6. //
  7. // Implementation of class TControl.  This defines the basic behavior of all
  8. // controls.
  9. //----------------------------------------------------------------------------
  10. #pragma hdrignore SECTION
  11. #include <owl/pch.h>
  12. #if !defined(OWL_CONTROL_H)
  13. # include <owl/control.h>
  14. #endif
  15.  
  16. OWL_DIAGINFO;
  17. #if defined(SECTION) && SECTION != 1
  18. DIAG_DECLARE_GROUP(OwlControl);
  19. #endif
  20.  
  21. #if !defined(SECTION) || SECTION == 1
  22.  
  23. //
  24. // General Controls diagnostic group
  25. //
  26. DIAG_DEFINE_GROUP_INIT(OWL_INI, OwlControl, 1, 0);
  27.  
  28. DEFINE_RESPONSE_TABLE1(TControl, TWindow)
  29.   EV_WM_PAINT,
  30.   EV_WM_COMPAREITEM,
  31.   EV_WM_DELETEITEM,
  32.   EV_WM_DRAWITEM,
  33.   EV_WM_MEASUREITEM,
  34. END_RESPONSE_TABLE;
  35.  
  36. //
  37. // Constructor for a TControl
  38. //
  39. TControl::TControl(TWindow*        parent,
  40.                    int             id,
  41.                    const char far* title,
  42.                    int x, int y, int w, int h,
  43.                    TModule*        module)
  44. {
  45.   // Initialize virtual base, in case the derived-most used default ctor
  46.   //
  47.   TWindow::Init(parent, title, module);
  48.  
  49.   Attr.Id = id;
  50.   Attr.X = x;
  51.   Attr.Y = y;
  52.   Attr.W = w;
  53.   Attr.H = h;
  54.   Attr.Style = WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP;
  55.   NativeUse = nuDontCare;
  56.  
  57.   TRACEX(OwlControl, OWL_CDLEVEL, "TControl constructed @" << (void*)this);
  58. }
  59.  
  60. //
  61. // Constructor for a TControl to be associated with a MS-Windows
  62. // interface element created by MS-Windows from a resource definition
  63. //
  64. // Data transfer is enabled for the TControl by default
  65. //
  66. TControl::TControl(TWindow*   parent,
  67.                    int        resourceId,
  68.                    TModule*   module)
  69. {
  70.   // Initialize virtual base, in case the derived-most used default ctor
  71.   //
  72.   TWindow::Init(parent, 0, module);
  73.  
  74.   if (HiUint16(uint32(Title)))
  75.     delete[] Title;     // Free memory allocated by TWindow's constructor
  76.   Title = 0;
  77.  
  78.   SetFlag(wfFromResource);
  79.   memset(&Attr, 0x0, sizeof(Attr));
  80.   Attr.Id = resourceId;
  81.   EnableTransfer();
  82.   NativeUse = nuDontCare;
  83.  
  84.   TRACEX(OwlControl, OWL_CDLEVEL, "TControl constructed from resource @" << (void*)this);
  85. }
  86.  
  87. //
  88. // Constructor to alias a non-OWL control
  89. //
  90. TControl::TControl(THandle handle, TModule* module)
  91. {
  92.   // Initialize virtual base, in case the derived-most used default ctor
  93.   //
  94.   TWindow::Init(handle, module);
  95.   NativeUse = nuDontCare;
  96.  
  97.   TRACEX(OwlControl, OWL_CDLEVEL, "TControl aliased @" << (void*)this <<
  98.     " to handle" << uint(handle));
  99. }
  100.  
  101. //
  102. //
  103. //
  104. TControl::~TControl()
  105. {
  106.   TRACEX(OwlControl, OWL_CDLEVEL, "TControl destructed @" << (void*)this);
  107. }
  108.  
  109. //
  110. // Intercept WM_PAINT to redirect from TWindow to the underlying control iff
  111. // this Owl object is just a wrapper for a predefined class.
  112. //
  113. void
  114. TControl::EvPaint()
  115. {
  116.   if (IsFlagSet(wfPredefinedClass))
  117.     DefaultProcessing();  // don't call TWindow::EvPaint()
  118.  
  119.   else
  120.     TWindow::EvPaint();
  121. }
  122.  
  123. //
  124. // Handles WM_COMPAREITEM message (for owner draw controls) by calling the
  125. // corresponding virtual function.
  126. //
  127. TResult
  128. TControl::EvCompareItem(uint /*ctrlId*/, COMPAREITEMSTRUCT far& compareInfo)
  129. {
  130.   return CompareItem(compareInfo);
  131. }
  132.  
  133. //
  134. // Function called when a WM_COMPAREITEM is sent to parent on our behalf
  135. //
  136. int
  137. TControl::CompareItem(COMPAREITEMSTRUCT far&)
  138. {
  139.   TRACEX(OwlControl, 1, "TControl::CompareItem() @" << (void*)this);
  140.   return 0;
  141. }
  142.  
  143. //
  144. // Handles WM_DELETEITEM message (for owner draw controls) by calling the
  145. // corresponding virtual function.
  146. //
  147. void
  148. TControl::EvDeleteItem(uint /*ctrlId*/, DELETEITEMSTRUCT far& deleteInfo)
  149. {
  150.   DeleteItem(deleteInfo);
  151. }
  152.  
  153. //
  154. // Function called when a WM_DELETEITEM is sent to parent on our behalf
  155. //
  156. void
  157. TControl::DeleteItem(DELETEITEMSTRUCT far&)
  158. {
  159.   TRACEX(OwlControl, 1, "TControl::DeleteItem() @" << (void*)this);
  160. }
  161.  
  162. //
  163. // Handles WM_MEASUREITEM message (for owner draw controls) by calling the
  164. // corresponding virtual function.
  165. //
  166. void
  167. TControl::EvMeasureItem(uint /*ctrlId*/, MEASUREITEMSTRUCT far& measureInfo)
  168. {
  169.   MeasureItem(measureInfo);
  170. }
  171.  
  172. //
  173. // Function called when a WM_MEASUREITEM is sent to parent on our behalf
  174. //
  175. void
  176. TControl::MeasureItem(MEASUREITEMSTRUCT far&)
  177. {
  178.   TRACEX(OwlControl, 1, "TControl::MeasureItem() @" << (void*)this);
  179. }
  180.  
  181. //
  182. // Handles WM_DRAWITEM message (for owner draw controls) by calling the
  183. // corresponding virtual function.
  184. //
  185. void
  186. TControl::EvDrawItem(uint /*ctrlId*/, DRAWITEMSTRUCT far& drawInfo)
  187. {
  188.   DrawItem(drawInfo);
  189. }
  190.  
  191. //
  192. // Function called when a WM_DRAWITEM is sent to parent on our behalf. This
  193. // is in turn broken up into one of three draw events.
  194. //
  195. void
  196. TControl::DrawItem(DRAWITEMSTRUCT far& drawInfo)
  197. {
  198.   switch (drawInfo.itemAction) {
  199.     case ODA_DRAWENTIRE:
  200.       ODADrawEntire(drawInfo);
  201.       break;
  202.  
  203.     case ODA_FOCUS:
  204.       ODAFocus(drawInfo);
  205.       break;
  206.  
  207.     case ODA_SELECT:
  208.       ODASelect(drawInfo);
  209.       break;
  210.   }
  211. }
  212.  
  213. //
  214. // Function called when the entire owner-draw control needs to be redrawn
  215. //
  216. // Will usually be redefined by descendants of TControl which use owner draw
  217. // style
  218. //
  219. void
  220. TControl::ODADrawEntire(DRAWITEMSTRUCT far&)
  221. {
  222.   TRACEX(OwlControl, 1, "TControl::ODADrawEntire() @" << (void*)this);
  223. }
  224.  
  225. //
  226. // Function called when an owner-draw control gains or loses focus
  227. //
  228. // Will usually be redefined by descendants of TControl which use owner draw
  229. // style
  230. //
  231. void
  232. TControl::ODAFocus(DRAWITEMSTRUCT far&)
  233. {
  234.   TRACEX(OwlControl, 1, "TControl::ODAFocus() @" << (void*)this);
  235. }
  236.  
  237. //
  238. // Function called when an owner-draw control's selection status changes
  239. //
  240. // Will usually be redefined by descendants of TControl which use owner draw
  241. // style
  242. //
  243. void
  244. TControl::ODASelect(DRAWITEMSTRUCT far&)
  245. {
  246.   TRACEX(OwlControl, 1, "TControl::ODASelect() @" << (void*)this);
  247. }
  248.  
  249. #endif
  250. #if !defined(SECTION) || SECTION == 2
  251.  
  252. IMPLEMENT_STREAMABLE1(TControl, TWindow);
  253.  
  254. #if !defined(BI_NO_OBJ_STREAMING)
  255.  
  256. //
  257. //
  258. //
  259. void*
  260. TControl::Streamer::Read(ipstream& is, uint32 version) const
  261. {
  262.   TControl* o = GetObject();
  263.   ReadBaseObject((TWindow*)o, is);
  264.  
  265.   if (version > 1) {
  266.     int nu;
  267.     is >> nu;
  268.     o->NativeUse = TNativeUse(nu);  
  269.   }
  270.  
  271.   return o;
  272. }
  273.  
  274. //
  275. //
  276. //
  277. void
  278. TControl::Streamer::Write(opstream& os) const
  279. {
  280.   TControl* o = GetObject();
  281.   WriteBaseObject((TWindow*)o, os);
  282.   os << o->NativeUse;  // version 2
  283. }
  284. #endif  // if !defined(BI_NO_OBJ_STREAMING)
  285.  
  286. #endif
  287.